package com.rmt.www.daoImpl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import com.rmt.www.dao.HistoryDao;
import com.rmt.www.dao.TestArtifactHistoryDao;
import com.rmt.www.vo.Artifact;
import com.rmt.www.vo.History;
import com.rmt.www.vo.TestArtifactHistory;

public class TestArtifactHistoryDaoImpl implements TestArtifactHistoryDao {

	private JdbcTemplate jdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	@SuppressWarnings("unchecked")
	public List<TestArtifactHistory> getTestArtifactHistoriesById(int id) {
		return (List<TestArtifactHistory>)(this.jdbcTemplate.query("select * from testartifacthistory where testartifactid=?",
				new Object[]{id}, 
				new int[]{java.sql.Types.INTEGER}, 
				new TestArtifactHistoryRowMapper()));
	}

	public void insertTestArtifactHistory(TestArtifactHistory history) {
		jdbcTemplate.update("insert into testartifacthistory(pid,testcasetype,title,priority,precondition,input,testdata,steps,expectedresult,postcondition,effort,cost,risk,comment,createrid,createdtime,updaterid,updatedtime,updatedtimes,version,testartifactid,status) " +
							"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", 
							new Object[]{
								history.getPid(),
								history.getTestcasetype(),
								history.getTitle(),
								history.getPriority(),
								history.getPrecondition(),
								history.getInput(),
								history.getTestdata(),
								history.getSteps(),
								history.getExpectedresult(),
								history.getPostcondition(),
								history.getEffort(),
								history.getCost(),
								history.getRisk(),
								history.getComment(),
								history.getCreaterid(),
								history.getCreatedtime(),
								history.getUpdaterid(),
								history.getUpdatedtime(),
								history.getUpdatedtimes(),
								history.getVersion(),
								history.getTestartifactid(),
								history.getStatus()
							},new int[] {
								java.sql.Types.INTEGER,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.INTEGER,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.INTEGER,
								java.sql.Types.TIMESTAMP,
								java.sql.Types.INTEGER,
								java.sql.Types.TIMESTAMP,
								java.sql.Types.INTEGER,
								java.sql.Types.VARCHAR,
								java.sql.Types.INTEGER,
								java.sql.Types.VARCHAR
							});
	}

	
}
